package org.example.bobofish.common.exception;

import lombok.Getter;
import lombok.Setter;

/**
 * @author : yuxiong
 * @date : 2025/6/10
 */
@Getter
public class BizException extends RuntimeException{

    @Setter
    private int code;
    private final String msgTemplate;
    public static BizException build(int code, String msgTemplate, String... args) {
        String message = msgTemplate;
        if (args != null && args.length > 0) {
            Object[] params = new Object[args.length];
            System.arraycopy(args, 0, params, 0, args.length);
            message = String.format(msgTemplate, params);
        }
        return new BizException(code, msgTemplate, message);
    }

    public BizException(int code, String msgTemplate, String message) {
        super(message);
        this.code = code;
        this.msgTemplate = msgTemplate;
    }
}
